# Maintainer: Felix Xing (Felixaszx) <felixaszx@outlook.com>

_realname=meshoptimizer
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.23
pkgrel=1
pkgdesc="Mesh optimization library that makes meshes smaller and faster to render (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://meshoptimizer.org/"
msys2_repository_url="https://github.com/zeux/meshoptimizer"
msys2_references=()
license=("spdx:MIT")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/zeux/meshoptimizer/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('ac574107dd7e532ecfbea208fff9cd18fbcd1687f1d540ff8a798624ada453e0')

build() {
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DMESHOPT_BUILD_DEMO=OFF \
      -DMESHOPT_BUILD_SHARED_LIBS=ON \
      -DMESHOPT_BUILD_GLTFPACK=ON \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  cd "${srcdir}"

  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
